﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using BOHVote.BLL;

namespace BOH.Reports
{
    public partial class ReportUnitH : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ApplyPeriod"] != null)
                {
                    labPeriod.Text = Session["ApplyPeriod"].ToString();
                    ShowReport(Session["ApplyPeriod"].ToString());
                }

            }
        }

        public void ShowReport(string strApplyPeriod)
        {
            if (Request.QueryString["GovrenID"] != null)
            {
                string strGovrenID = Request.QueryString["GovrenID"].ToString();
                DataSet dst = ReportClass.dstUnitHeightApply(strApplyPeriod, strGovrenID);

                string SubjectTotal = "合计";
                int AllTotalApply = 0, AllTotalPass = 0, AllHeightApply = 0, AllHeightPass = 0;
                int AllviceApply = 0, AllvicePass = 0;

                double AllTotalPassRate = 0, AllHeightPassRate = 0, AllvicePassRate = 0;

                foreach (DataRow dr in dst.Tables[0].Rows)
                {
                    HtmlTableRow row = new HtmlTableRow();
                    row.Style.Add("height", "22px");
                    //HtmlTableCell cell1 = new HtmlTableCell();
                    //cell1.InnerText = dr["SequenceNo"].ToString();
                    //cell1.Align = "Center";
                    //row.Cells.Add(cell1);

                    HtmlTableCell cell1 = new HtmlTableCell();
                    cell1.InnerText = dr["UnitID"].ToString();
                    cell1.Align = "Center";
                    row.Cells.Add(cell1);

                    HtmlTableCell cell2 = new HtmlTableCell();
                    cell2.InnerHtml = dr["UnitName"].ToString();
                    cell2.Align = "Left";
                    row.Cells.Add(cell2);

                    #region <<  所有申报  >>
                    if (!String.IsNullOrEmpty(dr["TotalApply"].ToString()) && dr["TotalApply"].ToString().Trim() != "0")
                    {
                        HtmlTableCell cell3 = new HtmlTableCell();
                        cell3.InnerText = dr["TotalApply"].ToString();
                        cell3.Align = "Center";
                        cell3.Style.Add("font-weight", "bold");
                        cell3.Style.Add("background-color", "#ffff99");
                        row.Cells.Add(cell3);

                        HtmlTableCell cell4 = new HtmlTableCell();
                        cell4.InnerText = dr["TotalPass"].ToString();
                        cell4.Align = "Center";
                        cell4.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell4);

                        HtmlTableCell cell5 = new HtmlTableCell();
                        cell5.InnerText = dr["TotalPassRate"].ToString() + "%";
                        cell5.Align = "right";
                        cell5.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell5);

                        AllTotalApply += Convert.ToInt32(dr["TotalApply"].ToString());
                        AllTotalPass += Convert.ToInt32(dr["TotalPass"].ToString());
                    }
                    else
                    {
                        HtmlTableCell cell3 = new HtmlTableCell();
                        cell3.InnerText = "";
                        cell3.Style.Add("background-color", "#ffff99");
                        row.Cells.Add(cell3);

                        HtmlTableCell cell4 = new HtmlTableCell();
                        cell4.InnerText = "";
                        row.Cells.Add(cell4);

                        HtmlTableCell cell5 = new HtmlTableCell();
                        cell5.InnerText = "";
                        row.Cells.Add(cell5);
                    }
                    #endregion

                    #region  <<  正高申报  >>
                    if (!String.IsNullOrEmpty(dr["HeightApply"].ToString()) && dr["HeightApply"].ToString().Trim() != "0")
                    {

                        HtmlTableCell cell6 = new HtmlTableCell();
                        cell6.InnerText = dr["HeightApply"].ToString();
                        cell6.Align = "Center";
                        cell6.Style.Add("font-weight", "bold");
                        cell6.Style.Add("background-color", "#99ccff");
                        row.Cells.Add(cell6);

                        HtmlTableCell cell7 = new HtmlTableCell();
                        cell7.InnerText = dr["HeightPass"].ToString();
                        cell7.Align = "Center";
                        cell7.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell7);

                        HtmlTableCell cell8 = new HtmlTableCell();
                        cell8.InnerText = dr["HeightPassRate"].ToString() + "%";
                        cell8.Align = "right";
                        cell8.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell8);

                        AllHeightApply += Convert.ToInt32(dr["HeightApply"].ToString());
                        AllHeightPass += Convert.ToInt32(dr["HeightPass"].ToString());
                    }
                    else
                    {
                        HtmlTableCell cell6 = new HtmlTableCell();
                        cell6.InnerText = "";
                        cell6.Style.Add("background-color", "#99ccff");
                        row.Cells.Add(cell6);

                        HtmlTableCell cell7 = new HtmlTableCell();
                        cell7.InnerText = "";
                        row.Cells.Add(cell7);

                        HtmlTableCell cell8 = new HtmlTableCell();
                        cell8.InnerText = "";
                        row.Cells.Add(cell8);
                    }
                    #endregion


                    #region <<  副高 申报  >>
                    if (!String.IsNullOrEmpty(dr["viceApply"].ToString()) && dr["viceApply"].ToString().Trim() != "0")
                    {
                        HtmlTableCell cell9 = new HtmlTableCell();
                        cell9.InnerText = dr["viceApply"].ToString();
                        cell9.Align = "Center";
                        cell9.Style.Add("font-weight", "bold");
                        cell9.Style.Add("background-color", "#ffcc99");
                        row.Cells.Add(cell9);

                        HtmlTableCell cell10 = new HtmlTableCell();
                        cell10.InnerText = dr["vicePass"].ToString();
                        cell10.Align = "Center";
                        cell10.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell10);

                        HtmlTableCell cell11 = new HtmlTableCell();
                        cell11.InnerText = dr["vicePassRate"].ToString() + "%";
                        cell11.Align = "right";
                        cell11.Style.Add("font-weight", "bold");
                        row.Cells.Add(cell11);

                        AllviceApply += Convert.ToInt32(dr["viceApply"].ToString());
                        AllvicePass += Convert.ToInt32(dr["vicePass"].ToString());
                    }
                    else
                    {
                        HtmlTableCell cell9 = new HtmlTableCell();
                        cell9.InnerText = "";
                        cell9.Style.Add("background-color", "#ffcc99");
                        row.Cells.Add(cell9);

                        HtmlTableCell cell10 = new HtmlTableCell();
                        cell10.InnerText = "";
                        row.Cells.Add(cell10);

                        HtmlTableCell cell11 = new HtmlTableCell();
                        cell11.InnerText = "";
                        row.Cells.Add(cell11);
                    }
                    #endregion

                    tabGovernReport.Rows.Add(row);
                }

                #region  <<  Add Total row  >>
                HtmlTableRow rowTotal = new HtmlTableRow();

                if (AllTotalApply != 0 && AllTotalPass != 0)
                {
                    AllTotalPassRate = Convert.ToDouble(AllTotalPass) / Convert.ToDouble(AllTotalApply);
                }
                else
                {
                    AllTotalPassRate = 0;
                }

                if (AllHeightApply != 0 && AllHeightPass != 0)
                {
                    AllHeightPassRate = Convert.ToDouble(AllHeightPass) / Convert.ToDouble(AllHeightApply);
                }
                else
                {
                    AllHeightPassRate = 0;
                }

                if (AllviceApply != 0 && AllvicePass != 0)
                {
                    AllvicePassRate = Convert.ToDouble(AllvicePass) / Convert.ToDouble(AllviceApply);
                }
                else
                {
                    AllvicePassRate = 0;
                }


                HtmlTableCell cellb = new HtmlTableCell();
                cellb.InnerText = string.Empty;
                rowTotal.Cells.Add(cellb);

                HtmlTableCell cellc = new HtmlTableCell();
                cellc.InnerText = SubjectTotal;
                cellc.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellc);

                HtmlTableCell celld = new HtmlTableCell();
                celld.InnerText = AllTotalApply.ToString();
                celld.Style.Add("background-color", "#ffff99");
                celld.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(celld);

                HtmlTableCell celle = new HtmlTableCell();
                celle.InnerText = AllTotalPass.ToString();
                celle.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(celle);

                HtmlTableCell cellf = new HtmlTableCell();
                cellf.InnerText = AllTotalPassRate.ToString("0.00%");
                cellf.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellf);

                HtmlTableCell cellg = new HtmlTableCell();
                cellg.InnerText = AllHeightApply.ToString();
                cellg.Style.Add("background-color", "#99ccff");
                cellg.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellg);

                HtmlTableCell cellh = new HtmlTableCell();
                cellh.InnerText = AllHeightPass.ToString();
                cellh.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellh);

                HtmlTableCell celli = new HtmlTableCell();
                celli.InnerText = AllHeightPassRate.ToString("0.00%");
                celli.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(celli);

                HtmlTableCell cellq = new HtmlTableCell();
                cellq.InnerText = AllviceApply.ToString();
                cellq.Style.Add("background-color", "#ffcc99");
                cellq.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellq);

                HtmlTableCell cellu = new HtmlTableCell();
                cellu.InnerText = AllvicePass.ToString();
                cellu.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellu);

                HtmlTableCell cellV = new HtmlTableCell();
                cellV.InnerText = AllvicePassRate.ToString("0.00%");
                cellV.Style.Add("font-weight", "bold");
                rowTotal.Cells.Add(cellV);


                tabGovernReport.Rows.Add(rowTotal);
                #endregion
            }
        }
    }
}
